package cn.iocoder.yudao.module.vos.service.secretrechargerecord;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.vos.controller.admin.secretrechargerecord.vo.*;
import cn.iocoder.yudao.module.vos.dal.dataobject.secretrechargerecord.SecretRechargeRecordDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.vos.dal.mysql.secretrechargerecord.SecretRechargeRecordMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.yudao.module.vos.enums.ErrorCodeConstants.*;

/**
 * 密钥充值记录 Service 实现类
 *
 * @author shijun
 */
@Service
@Validated
public class SecretRechargeRecordServiceImpl implements SecretRechargeRecordService {

    @Resource
    private SecretRechargeRecordMapper secretRechargeRecordMapper;

    @Override
    public Long createSecretRechargeRecord(SecretRechargeRecordSaveReqVO createReqVO) {
        // 插入
        SecretRechargeRecordDO secretRechargeRecord = BeanUtils.toBean(createReqVO, SecretRechargeRecordDO.class);
        secretRechargeRecordMapper.insert(secretRechargeRecord);

        // 返回
        return secretRechargeRecord.getId();
    }

    @Override
    public void updateSecretRechargeRecord(SecretRechargeRecordSaveReqVO updateReqVO) {
        // 校验存在
        validateSecretRechargeRecordExists(updateReqVO.getId());
        // 更新
        SecretRechargeRecordDO updateObj = BeanUtils.toBean(updateReqVO, SecretRechargeRecordDO.class);
        secretRechargeRecordMapper.updateById(updateObj);
    }

    @Override
    public void deleteSecretRechargeRecord(Long id) {
        // 校验存在
        validateSecretRechargeRecordExists(id);
        // 删除
        secretRechargeRecordMapper.deleteById(id);
    }

    @Override
        public void deleteSecretRechargeRecordListByIds(List<Long> ids) {
        // 删除
        secretRechargeRecordMapper.deleteByIds(ids);
        }


    private void validateSecretRechargeRecordExists(Long id) {
        if (secretRechargeRecordMapper.selectById(id) == null) {
            throw exception(SECRET_RECHARGE_RECORD_NOT_EXISTS);
        }
    }

    @Override
    public SecretRechargeRecordDO getSecretRechargeRecord(Long id) {
        return secretRechargeRecordMapper.selectById(id);
    }

    @Override
    public PageResult<SecretRechargeRecordDO> getSecretRechargeRecordPage(SecretRechargeRecordPageReqVO pageReqVO) {
        return secretRechargeRecordMapper.selectPage(pageReqVO);
    }

}